#include "RingQueue.hpp"
#include <unistd.h>

int count = 1;

void* productor(void* args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    while(true)
    {
        rq->Equeue(count);
        std::cout << "生产者生产一个数据: " << count << std::endl;
        count++;
    }

    return nullptr;
}

void* consumer(void* args)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(args);
    while(true)
    {
        int* out = new int;
        rq->Pop(out);
        sleep(1);
        std::cout << "* * * * 消费者消耗一个数据: " << *out << std::endl;

    }
    return nullptr;
}

int main()
{
    
    pthread_t p,c;
    RingQueue<int>* rq = new RingQueue<int>;

    pthread_create(&p, nullptr, productor, rq);

    pthread_create(&c, nullptr, consumer, rq);

    pthread_join(p, nullptr);

    pthread_join(c, nullptr);

    return 0;
}